package com.wtwd.campus.attendancenetty;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.timeout.IdleStateEvent;
import io.netty.handler.timeout.IdleStateHandler;

import java.util.concurrent.TimeUnit;

/**
 * 空闲检测处理
 */
public class ServerIdleHandler extends IdleStateHandler {
	/**
     * 设置空闲检测时间为 360s  设备心跳是3分钟一次
     */
    private static final int READER_IDLE_TIME = 360;
    public ServerIdleHandler() {
        super(READER_IDLE_TIME, 0, 0, TimeUnit.SECONDS);
    }

    @Override
    protected void channelIdle(ChannelHandlerContext ctx, IdleStateEvent evt) throws Exception {
        System.out.println(READER_IDLE_TIME + " 秒内没有读取到数据,关闭连接");        
        AttendanceChannelHandler.closeChannel(ctx.channel());
    }

}
